<template>
  <el-dialog
    class="task-pass-dialog"
    title="通过任务"
    width="400px"
    :visible.sync="dialogVisible"
    :close-on-click-modal="true"
    v-dialogDrag="true"
    append-to-body
    @open="handleDialogOpen"
    @closed="handleDialogClosed"
  >
    <el-form ref="rejectTaskFormRef" :model="formData" :rules="formRules" size="small" label-width="100px">
      <el-form-item label="签章类型" prop="useSign" label-width="80px">
        <el-radio-group v-model="formData.useSign">
          <el-radio label="0">无</el-radio>
          <el-radio label="1">CMA</el-radio>
          <el-radio label="2">CNAS</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>

    <div class="dialog-footer" slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="handleConfirm">确 定</el-button>
      <el-button @click="dialogVisible = false">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { handle } from "@/api/testItem/detectionResult";

export default {
  name: 'TaskPassDialog',
  components: {},
  dicts: [],
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    row: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      formData: {},
      formRules: {},
      btnLoading: false,
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.show
      },
      set(value) {
        this.$emit('update:show', value)
      }
    }
  },
  created() {
    this.initFormData()
  },
  methods: {
    // 弹框打开时
    handleDialogOpen() {
    },
    // 弹框关闭时
    handleDialogClosed() {
      this.initFormData()
      this.$refs.rejectTaskFormRef.resetFields()
    },
    // 初始化表单数据
    initFormData() {
      this.formData = {
        useSign: '1',
      }
    },
    // 获取表单数据
    getFormData() {
      const data = JSON.parse(JSON.stringify(this.formData))
      data.id = this.row.taskDetectionEquipmentId
      data.operation = 1
      return data
    },
    // 点击确定
    handleConfirm() {
      this.$refs.rejectTaskFormRef.validate(valid => {
        if (!valid) return
        const data = this.getFormData()
        console.log('表单数据', data)
        handle(data).then(res => {
          this.$message.success('操作成功')
          this.dialogVisible = false
          this.$emit('pass-task-success', res.data)
        }).catch(err => {})
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.task-pass-dialog {

  ::v-deep .el-dialog__body {
    max-height: 70vh;
    overflow-y: auto;
  }

  ::v-deep .transfer {
    width: 100%;

    .el-transfer-panel {
      width: calc(calc(100% - 182px) / 2);
    }

    .el-transfer-panel__body {
      height: calc(70vh - 40px - 100px - 15px);
    }

    .el-transfer-panel__list {
      height: calc(100% - 32px - 15px);
    }
  }
}
</style>
